<!--
 * @Author: your name
 * @Date: 2021-03-29 22:36:56
 * @LastEditTime: 2021-04-30 02:04:36
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /medicine-web/src/components/TabSort/index.vue
-->
<template>
  <span class="tab-sort-container">
    <span class="font-pattern-3" style="margin-right: 14px;">{{sortLabel}}</span>
    <span :class="{ 'tab-sort-arrow': true, 'tab-sort-arrow__active': isActive == true }" @click.stop="sortStatus('up')"></span>
    <span :class="{ 'tab-sort-down': true, 'tab-sort-down__active': isActive == false }" @click.stop="sortStatus('down')"></span>
  </span>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
  name: 'tabSort',
  data () {
    return {
      isActive: null
    }
  },
  methods: {
    sortStatus (statusStr) {
      console.log('statusStr', statusStr)
      this.$action('resetSort', statusStr)
      this.$nextTick(() => {
        if (statusStr == 'up') {
          this.isActive = true
        } else {
          this.isActive = false
        }
        console.log('this.isActive', this.isActive)
        console.log('this.sortLabel', this.sortLabel)
        this.$emit('sortStatus', { tab: this.sortLabel, active: this.isActive })
      })
    }
  },
  props: {
    sortLabel: {
      type: String,
      default: ''
    }
  },
  computed: {
    ...mapGetters({
      resetSort: 'resetSort'
    })
  },
  watch: {
    resetSort (val) {
      if (val == 'up') {
        this.isActive = true
      } else if (val == 'down') {
        this.isActive = false
      } else {
        this.isActive = null
      }
    }
  }
}
</script>
<style lang="scss" scoped>
@import '~@/assets/styles/flex.scss';
@import '~@/assets/styles/common.scss';
.tab-sort-container {
  position: relative;
}
.tab-sort-arrow {
  position: absolute;
  width: 0;
  height: 0;
  right: 0;
  top: 4.5px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 5px solid #555555;
  cursor: pointer;
}
.tab-sort-arrow__active {
  position: absolute;
  width: 0;
  height: 0;
  right: 0;
  top: 4.5px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 5px solid #08adc1;
}
.tab-sort-down {
  position: absolute;
  right: 0;
  bottom: 4.5px;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid #555555;
  cursor: pointer;
}
.tab-sort-down__active {
  position: absolute;
  right: 0;
  bottom: 4.5px;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid #08adc1;
  cursor: pointer;
}
</style>